package com.demo.algorithms;

import java.util.Arrays;

public class QuickSortTest {
	public static void main(String[] args){
		int[] num = {1,4,2,6,8,3,5};
		quicksort(num,0,num.length-1);
		System.out.println(Arrays.toString(num));
	}
	public static int partition(int[] num,int low,int high){
		int temp = num[low];
		while(low<high){
			while(low<high&&num[high]>temp) high--;
				num[low] = num[high];
			while(low<high&&num[low]<temp) low++;
				num[high] = num[low];
		}
		num[low] = temp;
		return low;
	}
	public static void quicksort(int[] num,int low,int high){
		if(low<high){
			int middle = partition(num,low,high);
			quicksort(num,low,middle-1);
			quicksort(num,middle+1,high);
		}
	}

}
